package com.tv.nextin.adapter;

import java.util.ArrayList;

import com.tv.nextin.R;
import com.tv.nextin.Utils.Utils;
import com.tv.nextin.bean.Bussiness;
import com.tv.nextin.bean.Category;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

public class ListBussinessAdapter extends ArrayAdapter<Bussiness>{
	
	Context context;
	ArrayList<Bussiness> bussinesses = new ArrayList<Bussiness>();
	
	public ListBussinessAdapter(Context context, ArrayList<Bussiness> bussinesses){
		super(context, R.layout.item_bussiness, bussinesses);
		this.context = context;
		this.bussinesses = bussinesses;
	}
	

	@Override
	public int getCount() {
		return bussinesses.size();
	}


	@Override
	public long getItemId(int position) {
		return position;
	}
	
	

	@Override
	public Bussiness getItem(int position) {
		return bussinesses.get(position);
	}


	@Override
	public View getView(int postioin, View v, ViewGroup parent) {
		Holder holder = null;
        
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        
        if (v == null) {
            v = mInflater.inflate(R.layout.item_bussiness, null);
            holder = new Holder();
            holder.txtName = (TextView) v.findViewById(R.id.txt_name);
            holder.distance = (TextView) v.findViewById(R.id.txt_distance);
            holder.address = (TextView) v.findViewById(R.id.txt_address);
            holder.hourSupport = (TextView) v.findViewById(R.id.txt_hour);
            holder.viewMore = (TextView) v.findViewById(R.id.btn_view_more);
            
            v.setTag(holder);
            
            
            
           /* holder.txtName.setTypeface(Utils.getTypefaceRegular(context));
            holder.distance.setTypeface(Utils.getTypefaceRegular(context));
            holder.address.setTypeface(Utils.getTypefaceRegular(context));
            holder.hourSupport.setTypeface(Utils.getTypefaceRegular(context));
            holder.viewMore.setTypeface(Utils.getTypefaceRegular(context));*/
            
        } else {
            holder = (Holder) v.getTag();
        }
        
        Bussiness bussiness = bussinesses.get(postioin);
        
        holder.txtName.setText(bussiness.getNameBussiness());
        holder.distance.setText(bussiness.getDistance());
        holder.address.setText(bussiness.getAddress());
        holder.hourSupport.setText(bussiness.getHourSupport());
        
        
		return v;
	}
	
	class Holder{
		TextView txtName, distance, address, hourSupport, viewMore;
	}


}
